<?php
class CC_Form_FlagSelect extends Zend_Form_Element_Select
{
    /** @var \Doctrine\ORM\EntityManager */
    protected $_em;
    
    public function __construct($spec, \Doctrine\ORM\EntityManager $em,  $options = null)
    {
        $this->_em = $em;
        
        parent::__construct($spec, $options);
    }
    
    public function init()
    {
        if(!($this->_em instanceof Doctrine\ORM\EntityManager) || $this->_em === null)
            throw new Zend_Exception("No entity manager defined in '".__CLASS__."'");
            
        $dql = $this->_em->createQuery('SELECT partial f.{id,name} FROM CC\Entity\Flag f ORDER BY f.name ASC');
        $flags = $dql->getResult();
        
        $this->addMultiOption('', 'Please select a flag...');
        foreach($flags as $flag)
            $this->addMultiOption($flag->getId(), $flag->getName());
        
        parent::init();
    }
}
?>